<template>
  <div class="userbar">
    <div class="right">
      <span class="name">{{userInfo.realname}},</span>
      <span>{{sayHello}}</span>
      <!-- <router-link to="/">我的任务<i class="num">3</i></router-link> -->
      <!-- <span class="split"></span> -->
      <router-link :to="{name: 'EditUser', params: {uid: userInfo.uid}}">我的资料</router-link>
      <span class="split"></span>
      <a href="javascript:;" @click="handleSignOut">退出</a>
    </div>
  </div>
</template>
<script>
  export default {
    props: ['userInfo'],
    computed: {
      sayHello: function () {
        const date = new Date()
        const hour = date.getHours()
        if (hour >= 6 && hour < 12) {
          return '早上好!'
        } else if (hour >= 12 && hour < 18) {
          return '下午好!'
        } else if (hour >= 18 && hour < 24 || hour >= 0) {
          return '晚上好!'
        }
      }
    },
    methods: {
      handleSignOut () {
        localStorage.removeItem('UBToken')
        this.$router.push({name: 'Login'})
      }
    }
  }
</script>
